/** **********************************************************************************
 * @file    1.B.c
 * @mainpage
 * @date    2013-09-29 23:05
 * @author  Alexey Kulikov <alexeyqu@gmail.com>, group 376, DCAM MIPT
 * @version 1.00
 *
 * Check if given number can be divided by square value greater than 1.
 *
 * @par     The task.
 *          The program checks if the given number has square divisors greater than 1.
 *
 * @warning Number should be between 0 and 2^31.
**************************************************************************************/

#include <stdlib.h>
#include <stdio.h>
#include <limits.h>

#define DEBUG

#ifdef DEBUG
    #define DBG printf ("# "),
    #define ASSERT(cond)                                                              \
    if (!(cond))                                                                      \
    {                                                                                 \
        printf ("Critical failure in assertion '%s'! \nfile %s, line %d \n"           \
                "Now keep calm and EXTERMINATE! EXTERMINATE! EXTERMINATE!!!\n"        \
                , #cond, __FILE__, __LINE__);                                         \
        abort();                                                                      \
    }
#else
    #define DBG if (0)
    #define ASSERT(cond)
#endif

/** ********************************************************************************
 * has_square_divisor - checks if argument number has square divisors greater than 1
 *
 * @param   Number  Number to check for divisors
 *
 * @return  1 - divisor exists
 *          0 - divisor doesn't exist
************************************************************************************/
int has_square_divisor (long long int number);

int main()
{
    DBG printf ("C language test'07. \n");
    DBG printf ("1.B problem. \n");
    DBG printf ("Check if number has square divisors greater than 1. \n");
    DBG printf ("Enter number to check: \n-> ");

    long long int number = 0; //!< Number to check
    int res_input = 0; //!< Value that controls correct input

    res_input = scanf ("%lld", &number);
    ASSERT (res_input); ASSERT (number >= 0); ASSERT (number <= LONG_MAX);

    DBG printf ("Result: ");
    printf ("%s", (has_square_divisor (number))? "YES" : "NO");

    return 0;
}

int has_square_divisor (long long int number)
{
    int i = 0; //!< Counter

    for (i = 2; i*i <= number; i++)
    {
        if (number % (i*i) == 0) return 1;
    }

    return 0;
}
